#!/bin/bash

# 创建root用户
#/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongo localhost:27017/admin /root/mongdb/mongodb-linux-x86_64-4.1.3/route/create_root_user.js

# 创建普通用户
#/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongo localhost:27017/lagou_resume /root/mongdb/mongodb-linux-x86_64-4.1.3/route/create_lagou_gx_user.js

# 关闭配置节点、分片节点、路由节点
killall mongod
killall mongos

sleep 10

# 生成密钥文件并修改权限
rm /root/mongdb/mongodb-linux-x86_64-4.1.3/data/mongodb/testKeyFile.file
mkdir -p /root/mongdb/mongodb-linux-x86_64-4.1.3/data/mongodb
openssl rand -base64 756 > /root/mongdb/mongodb-linux-x86_64-4.1.3/data/mongodb/testKeyFile.file
chmod 600 /root/mongdb/mongodb-linux-x86_64-4.1.3/data/mongodb/testKeyFile.file

echo "" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17017.conf
echo "auth=true" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17017.conf
echo "keyFile=/root/mongdb/mongodb-linux-x86_64-4.1.3/data/mongodb/testKeyFile.file" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17017.conf

echo "" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17018.conf
echo "auth=true" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17018.conf
echo "keyFile=/root/mongdb/mongodb-linux-x86_64-4.1.3/data/mongodb/testKeyFile.file" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17018.conf

echo "" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17019.conf
echo "auth=true" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17019.conf
echo "keyFile=/root/mongdb/mongodb-linux-x86_64-4.1.3/data/mongodb/testKeyFile.file" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17019.conf

echo "" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37017.conf
echo "auth=true" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37017.conf
echo "keyFile=/root/mongdb/mongodb-linux-x86_64-4.1.3/data/mongodb/testKeyFile.file" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37017.conf

echo "" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37018.conf
echo "auth=true" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37018.conf
echo "keyFile=/root/mongdb/mongodb-linux-x86_64-4.1.3/data/mongodb/testKeyFile.file" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37018.conf

echo "" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37019.conf
echo "auth=true" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37019.conf
echo "keyFile=/root/mongdb/mongodb-linux-x86_64-4.1.3/data/mongodb/testKeyFile.file" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37019.conf

echo "" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47017.conf
echo "auth=true" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47017.conf
echo "keyFile=/root/mongdb/mongodb-linux-x86_64-4.1.3/data/mongodb/testKeyFile.file" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47017.conf

echo "" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47018.conf
echo "auth=true" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47018.conf
echo "keyFile=/root/mongdb/mongodb-linux-x86_64-4.1.3/data/mongodb/testKeyFile.file" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47018.conf

echo "" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47019.conf
echo "auth=true" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47019.conf
echo "keyFile=/root/mongdb/mongodb-linux-x86_64-4.1.3/data/mongodb/testKeyFile.file" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47019.conf

echo "" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/route/route-27017.conf
echo "keyFile=/root/mongdb/mongodb-linux-x86_64-4.1.3/data/mongodb/testKeyFile.file" >> /root/mongdb/mongodb-linux-x86_64-4.1.3/route/route-27017.conf

echo "/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17017.conf"
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17017.conf

echo "/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17018.conf"
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17018.conf

echo "/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17019.conf"
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/config/config-17019.conf

echo "/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37017.conf"
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37017.conf

echo "/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37018.conf"
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37018.conf

echo "/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37019.conf"
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard1/shard1-37019.conf

echo "/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47017.conf"
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47017.conf

echo "/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47018.conf"
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47018.conf

echo "/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47019.conf"
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongod -f /root/mongdb/mongodb-linux-x86_64-4.1.3/shard/shard2/shard2-47019.conf

echo "/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongos -f /root/mongdb/mongodb-linux-x86_64-4.1.3/route/route-27017.conf"
/root/mongdb/mongodb-linux-x86_64-4.1.3/bin/mongos -f /root/mongdb/mongodb-linux-x86_64-4.1.3/route/route-27017.conf
